package com.applet.user.controller;


import com.applet.dto.UserLoginDTO;
import com.applet.result.Result;
import com.applet.user.service.UserService;
import com.applet.vo.UserLoginVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 微信端用户 controller
 */
@Slf4j
@RestController
@RequestMapping("/user/user")
public class UserController {


    @Resource
    private UserService userService;



    /**
     * C端-用户登录
     */
    @CacheEvict
    @PostMapping("/login")
    public Result appLetUserLogin(@RequestBody @Validated UserLoginDTO userLoginDTO){
        log.info("C端用户模块 - 登录授权码: {}", userLoginDTO.getCode());
        UserLoginVO userLoginVO = userService.wxLogin(userLoginDTO);
        return Result.success(userLoginVO);
    }



    /**
     * C端-用户登出
     */
    @PostMapping("/logout")
    public Result appLetUserLogout(){
        System.out.println("C端用户登出成功");
        return Result.success();
    }



}
